package com.xbh.management.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xbh.management.mapper.MenuMapper;
import com.xbh.management.model.ManMenu;
import com.xbh.management.model.ManRole;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: management-center
 * @description:
 * @author: 许宝华
 * @create: 2021-10-01 15:25
 */

@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper,ManMenu> implements MenuService {
    /**
     * 查询所有的菜单
     * @return
     */
    @Override
    public List<ManMenu> queryAllMenu() {
        LambdaQueryWrapper<ManMenu> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ManMenu::getDeleted,0);
        return this.baseMapper.selectList(wrapper);
    }

    /**
     * 根据id查看菜单信息
     * @param menuId
     * @return
     */
    @Override
    public ManMenu queryMenuWithMenuId(Long menuId) {
        return this.baseMapper.selectById(menuId);
    }

    @Override
    public int saveMenu(ManMenu menu) {
        return this.baseMapper.insert(menu);
    }

    @Override
    public int updateMenu(ManMenu menu) {
        return this.baseMapper.updateById(menu);
    }

    @Override
    public int deleteMenuByMenuIds(String menuIds) {
        String[] menuIdArray = menuIds.split(",");
        List<String> menuIdList = Arrays.stream(menuIdArray).collect(Collectors.toList());
        return this.baseMapper.deleteMenuByMenuIds(menuIdList);
    }

    /**
     * 查询当前菜单属于多少个角色
     * @param menuId
     * @return
     */
    @Override
    public List<ManRole> queryAllMenuRelationRole(Long menuId) {
        return this.baseMapper.queryAllMenuRelationRole(menuId);
    }
}
